package com.songlanyun.modules.exception;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.songlanyun.common.drive.IntegerEnum;


import java.util.Objects;

/**
 * 维护错误码之后也要维护错误描述
 * 1.错误码定义规则为5个数字
 */
public enum GoodsExceptionEnum implements IntegerEnum<Integer> {
    CATEGORY_NAME_REPEAT(20001, "分类名称重复"),
    CATEGORY_NOT_EXISTS(20002, "分类不存在"),
    CATEGORY_PARENT_NOT_EXISTS(20003, "商品分类上级不存在"),
    CATEGORY_SECOND_SAFE(20004, "商品分类只能添加两级"),
    CATEGORY_REMOVE_SAFE(20005, "当前商品分类下有子分类不能删除"),
    CATEGORY_SELECT_SELF(20006, "商品分类上级不能是自己"),

    PRODUCT_GROUP_NAME_REPEAT(20010, "商品分组名称重复"),
    PRODUCT_GROUP_NOT_EXISTS(20011, "商品分组不存在"),
    PRODUCT_GROUP_PARENT_NOT_EXISTS(20012, "商品分组上级不存在"),
    PRODUCT_GROUP_SECOND_SAFE(20013, "商品分组只能添加两级"),
    PRODUCT_GROUP_SHOP_SAFE(20014, "只能操作自己店铺的商品分组"),
    PRODUCT_GROUP_REMOVE_SAFE(20015, "当前商品分组下有子分组不能删除"),
    PRODUCT_GROUP_SELECT_SECOND(20016, "商品分组必须选择二级分组"),
    PRODUCT_GROUP_SELECT_SELF(20016, "商品分组上级不能是自己"),

    PRODUCT_SKU_NAME_REPEAT(20021, "商品规格名称重复"),
    PRODUCT_SKU_NOT_EXISTS(20022, "商品规格不存在"),
    PRODUCT_SKU_PARENT_NOT_EXISTS(20022, "商品规格上级不存在"),
    PRODUCT_SKU_SECOND_SAFE(20023, "商品规格只能添加两级"),
    PRODUCT_SKU_SHOP_SAFE(20024, "只能操作自己店铺的商品规格"),
    PRODUCT_SKU_REMOVE_SAFE(20025, "当前规格下有子项目不能删除"),
    PRODUCT_SKU_SELECT_SELF(20026, "规格上级不能是自己"),

    SINGLE_GOODS_NOT_EXISTS(20031, "单品不存在"),
    SINGLE_GOODS_SHOP_SAFE(20034, "只能操作自己店铺的单品"),
    SINGLE_GOODS_STOCK_SAFE(20035, "单品[%s]库存不足"),


    GOODS_NOT_EXISTS(20041, "商品不存在"),
    NEED_GOODS_GROUP(20041, "创建商品时必须选择商家店铺的商品分组"),
    NEED_GOODS_SKU(20042, "创建商品时必须要有商品规格"),
    GOODS_AUTH_SHOP_REPEAT(20043, "商品已有经营权限"),
    GOODS_SHOP_SAFE(20044, "只能操作自己店铺的商品"),
    PLATFORM_GOODS_AUTH(20045, "只有平台商品才可以代销"),
    NOT_CANCEL_SELF_GOODS(20046, "不能取销自营权限"),
    NOT_PROXY_AUTH(20047, "该商家不具备此商品的经营权限"),
    PUBLISH_AUTH_NOT_EXISTS(20048, "数据异常,发布的经营权限丢"),
    GOODS_VERIFY_NOT(20049, "商品审核不通过"),
    GOODS_NOT_ADDED(20050, "商品未上架"),
    PROXY_GOODS_NOT_ADD_CART(20051, "代销商品不能加入购物车"),
    GOODS_SKU_NOT_EXISTS(20052, "商品规格无效"),
    SINGLE_GOODS_GOODS_SKU_UNIQUE(20053, "单品只能被一个sku关联"),
    GOODS_LIMIT_ERROR(20054, "商品限购,每个会员只能买%d个商品"),
	OPERATION_NOT_NULL(20055, "操作指令不能为空"),
    CARD_NOT_EXIST(20056, "转入卡不能为空"),
    SINGLE_GOODS_STOCK_NOT_EXISTS(20057, "库存不存在"),
    GOODS_LIMIT_BUY(20058, "商品限购"),
    SECKILL_GOODS_STOCK_NO(20059, "该秒杀商品库存不足"),
    GROUPBUY_GOODS_STOCK_NO(20060, "该拼团商品库存不足"),

    DEFAULT_FREIGHT_TEMPLATE_UNIQUE(20061, "店铺的默认运费模板只能有一条"),
    FREIGHT_TEMPLATE_NOT_EXISTS(20062, "运费模板不存在"),
    FREIGHT_TEMPLATE_RULE_NOT_EXISTS(20063, "运费规则不存在"),
    DEFAULT_FREIGHT_TEMPLATE_RULE_UNIQUE(20064, "默认运费规则只能有一条"),
    DEFAULT_FREIGHT_TEMPLATE_RULE_NEED(20065, "不能删除默认规则"),
    DEFAULT_FREIGHT_TEMPLATE_NEED(20066, "默认运费模板必须有一条"),
    FREIGHT_TEMPLATE_COUNT(20067, "您的运费模板已满10条"),
    FREIGHT_TEMPLATE_RULE_COUNT(20068, "您的模板规则已满10条"),
    PLATFORM_SHOP_ABLE_PROXY(20069, "只有平台店可以设置是否代销"),
    CARD_NOT_UP(20070, "转入卡没有上架"),
    POINT_GOODS_NOT_PROXY(20071, "积分商品不能代销"),
    FREIGHT_TEMPLATE_RELEVANCE_GOODS(20072, "模板已关联了商品，不允许删除"),
    MARKET_PRICE_HEIGHT(20073, "市场价不能小于销售价"),
    SERVICE_MARKET_PRICE_HEIGHT(20074, "服务项目的市场价必须高于销售价"),
    POINT_EXCHANGE_GOODS_NOT_CART(20075, "积分兑换商品不放在购物车")
    ;


    private Integer code;
    private String msg;

    GoodsExceptionEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @JsonCreator
    public static GoodsExceptionEnum getByCode(int code) {
        for (GoodsExceptionEnum value : GoodsExceptionEnum.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }
}
